import { create } from "domain";

const ADD = "新增";
const MODIFY = "修改";
const DELETE = "删除";
const INFO = "详情";
const tablePageSize = typeof getPageSize === "function" ? getPageSize() : 10;
export const manage = {
  data() {
    return {
      dataList: [],
      headList: [],
      btnListRow: [],
      loading: false,
      selectData: {},
      // 功能
      title: null,
      order: null,
      //分页和排序
      pageOrder: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: tablePageSize,
        currentPage: 1
      },
      //当前选中行
      currentRow: null,
    }
  },
  methods: {
    //按钮显隐
    btnShow(btn) {
      return this.currentRow != null || btn === ADD
    },
    //分页和排序
    pageChange(value) {
      this.$store.state.isloading = true;
      this.pageOrder = value;
      this.getData();
    },
    //获取当前选中行
    selectRow(row, order) {
      this.currentRow = row;
      console.log("order", order);
      if (order !== "") {
        this.operate(order);
      }
    },
    //取消
    cancel() {
      this.$refs.dialog.close();
    },
    // close(){
    //   console.log('node',event)
    //   switch(this.order){
    //     case INFO:
    //       this.$refs.info.close();
    //     break;
    //     case MODIFY:
    //     case ADD:
    //       this.$refs.dialog.close();
    //   }
    // },
    //关闭详情
    infoClose() {
      this.$refs.info.close();
    },
    //条件查询
    btnSearch() {
      this.$store.state.isloading = true;
      this.getData();
    },
    // //报表类型
    // selectChange(val) {
    //   var nowMonth = new Date().getMonth();
    //   var nowYear = new Date().getYear();
    //   nowYear += (nowYear < 2000) ? 1900 : 0; 
    //   if(val === 'day'){
    //     this.reportform = '1';
    //     this.reportname='日报';
    //     this.selectData.ChddateGreaterAndEquals = new Date()
    //   } else if (val === 'mounth'){
    //     this.reportform = '2';
    //     this.reportname='月报';
    //     this.selectData.ChddateGreaterAndEquals = new Date(nowYear, nowMonth, 1)
    //   } else if (val === 'year'){
    //     this.reportform = '3';
    //     this.reportname='年报';
    //     this.selectData.ChddateGreaterAndEquals = new Date(nowYear, 0, 1)
    //   }
    // },

    //获取当月最后一天日期
    getLastDay(year,month) {         
      var new_year = year;    //取当前的年份          
      var new_month = month++;//取下一个月的第一天，方便计算（最后一天不固定）          
      if(month>12) {         
       new_month -=12;        //月份减          
       new_year++;            //年份增          
      }         
      var new_date = new Date(new_year,new_month,1);                //取当年当月中的第一天          
      return (new Date(new_date.getTime()-1000*60*60*24));//获取当月最后一天日期          
    }, 
    // 时间拼接
    dataSplicing(val){
      return val.getFullYear() + '年' + (val.getMonth() + 1) + '月' + val.getDate() + '日' + val.getHours() + ':' + val.getMinutes();
    },
    //时间拼接没有时分的
    dataSplicings(val){
      return val.getFullYear() + '年' + (val.getMonth() + 1) + '月' + val.getDate() + '日';
    },
    confirm(deleted,text) {
      let params = ''
      if(!text){
        params = '此操作将永久删除该数据, 是否继续?'
      }else{
        params = text
      }
      this.$confirm(params, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(callback => {
          deleted(callback);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  },
  computed: {
    isDisabled() {
      //console.log(this.order);
      return this.order === DELETE || this.order === INFO;
    }
  }

}
